import React, { useCallback, useState } from "react";
import Son from "./Son";

export default function UseMemoDemo() {

  const [num, setNum] = useState(3);
  const [price, setPrice] = useState(2.5);

  const changePrice = useCallback(() => {
    setPrice(price + 1);
  }, [price]);

  const changeNum=useCallback(()=>{
    setNum(num+1);
  },[num])

  return (
    <div>
      <h1>UseMemo</h1>
      <input type="button" value="修改价格" onClick={changePrice} />
      <input type="button" value="修改数量" onClick={changeNum} />
      <hr />
      <Son price={price} num={num}  ></Son>
    </div>
  );
}
